package com.wanmait.recruit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.mapper.IndustryMapper;
import com.wanmait.recruit.pojo.Industry;
import com.wanmait.recruit.service.IndustryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("industryService")
@Transactional(rollbackFor = Exception.class)
public class IndustryServiceImp implements IndustryService {
    @Resource
    private IndustryMapper industryMapper;
    @Override
    public PageInfo<Industry> finAll(String industryName, Integer pageNum) {
        int pageSize = 10;
        PageHelper.startPage(pageNum,pageSize);
        List<Industry> industries = industryMapper.finAll(industryName);
        PageInfo<Industry> pageInfo = new PageInfo<>(industries,11);
        return pageInfo;
    }

    @Override
    public void deleteById(Integer id) {
        industryMapper.deleteById(id);
    }

    @Override
    public Boolean isRename(String industryName) {
        Industry industry = industryMapper.isRename(industryName);
        if(industry==null){
            return true;
        }
        else {
            return false;
        }
    }

    @Override
    public List<Industry> findAll() {
        return industryMapper.finAll(null);
    }

    @Override
    public String selectByPositionTypeId(Integer industryId) {
        Industry industry = industryMapper.selectByPrimaryKey(industryId);
        return industry.getIndustryName();
    }

    @Override
    public ArrayList<Industry> selectFindAll() {
        return industryMapper.findAll2();
    }

    @Override
    public List<Industry> selectFindAllAndPositionType() {
        return industryMapper.findAllAndPositionTypes();
    }

    @Override
    public List<Industry> selectFindAllAndPositionTypeAndPosition() {
        return industryMapper.findAllAndPositionTypeAndPosition();
    }

    @Override
    public void insert(Industry object) {
        industryMapper.insert(object);
    }

    @Override
    public void delete(Industry object) {

    }

    @Override
    public void update(Industry object) {

    }

    @Override
    public PageInfo<Industry> search(int pageNum, int pageSize) {
        return null;
    }
}
